<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Chapter 7.&nbsp; Database Basics</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
<script type="text/javascript"><!--
google_ad_client = "pub-0203281046321155";
google_alternate_ad_url = "http://www.bookhtml.com/adbrite.htm";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="4867465545";
google_color_border = "FFFFFF";
google_color_link = "0000FF";
google_color_bg = "FFFFFF";
google_color_text = "000000";
google_color_url = "0000FF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-6-SECT-2.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-7-SECT-1.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="learnphpmysql-CHP-7"></a>
<h2 id="title-IDAOKHYH" class="docChapterTitle">Chapter 7. Database Basics</h2>
<p class="docText">We're now going to introduce you to basic database structure so that you have an understanding of databases. Adding MySQL to PHP and combining the applications for your dynamic web site is a great start. But, it helps tremendously to structure your database right. We'll give you a solid understanding of both database design and the language that's used to communicate with the database, SQL. The first step in setting up your database is to design how you'll store your data. Then, you'll learn how to add, view, and change data.</p>
<p class="docText">Databases are a repository for information. They excel at managing and manipulating structured information.<a name="IDX-CHP-7-0273"></a> 
 <span class="docEmphasis">Structured information</span> is a way to organize related pieces of information, which we discussed previously in our chapters on PHP. The basic types of structured information, which can also be called <span class="docEmphasis">data structures</span>, include:</p>
<ul><li><p class="docList">Files</p></li><li><p class="docList">Lists</p></li><li><p class="docList">Arrays</P></li><li><p class="docList">Records</P></LI><li><p class="docList">Trees</P></li><li><p class="docList">Tables</p></LI></ul>
<p class="docText">Each of these basic structures has many variations and allows for different operations to be performed on the data. An easy way to understand this concept is to think of the phone book. It's the most widespread database, and it contains several items of informationname, address, and phone number, as well as each phone subscriber in a particular area. Phone books have evolved, and some people may have bolded names, but for the most part, each entry in the phone book takes the same form.</p>
<p class="docText">If you think of the physical hardcopy phone book in similar terms as a database, the phone book is a <span class="docEmphasis">table</span>, which contains a <span class="docEmphasis">record</span> for each subscriber. Each subscriber record contains three <span class="docEmphasis">fields</span><a name="IDX-CHP-7-0274"></a> 
 (also known as <span class="docEmphasis">columns or attributes</span>): name, address, and
 phone number. These records are sorted alphabetically by the name field, which is called the <span class="docEmphasis">key field</span>. The phone book is alphabetized by last names first; look at <a class="docLink" href="#learnphpmysql-CHP-7-FIG-1">Figure 7-1</a> for how typical record and fields display in your database based on the phone book analogy.</P>
<a name="learnphpmysql-CHP-7-FIG-1"></a><p><center>
<h5 class="docFigureTitle">Figure 7-1. Phone book record and fields</H5>
<img border="0" alt="" width="543" height="89" SRC="images/learnphpmysql_0701.jpg">
</center></p><br>
<p class="docText">If you took the same data from the phone book and put it into a database, you could build queries such as who has the phone number 651-668-2251 or everyone in a specific zip code who has the last name Davis. This type of database is like a big spreadsheet; it can be called a <span class="docEmphasis">flat-file</span> database, which means each database is self-contained in a single table. Since the 1970s, relational<a name="IDX-CHP-7-0275"></a> 
 databases for managing data have replaced flat files.</p>
<p class="docText">The advantages of a fully relational RDBMS system are wide-ranging, including:</p>
<UL><LI><p class="docList">Unbeatable performance</p></li><li><p class="docList">Capability and power benefits</p></LI><li><p class="docList">Scalable and distributable systems</P></li><LI><p class="docList">Able to easily take advantage of new hardware technology</P></LI><li><p class="docList">Flexibility for evolution of users' data</p></li></ul>

<a href="11011536.html"><img src="images/pixel.jpg" alt="" width="1" height="1" border="0"></a></TD></TR></table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-6-SECT-2.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-7-SECT-1.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html>
